package com.anrongtec.zcpt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.model.NotifyList;

import java.util.List;

/**
 * Created by Administrator on 2015/12/13 0013.
 */
public class NotificationAdapter extends BaseAdapter {

    private List<NotifyList> notifyList;
    private Context context;

    public NotificationAdapter(List<NotifyList> notifyList, Context context) {
        this.notifyList = notifyList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return notifyList.size() > 0 ? notifyList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return notifyList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.item_notification_list, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_noti_title);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_noti_time);
            viewHolder.tv_content = (TextView) convertView.findViewById(R.id.tv_noti_context);
            viewHolder.tv_creator = (TextView) convertView.findViewById(R.id.tv_noti_creator);
            viewHolder.iv_state = (ImageView) convertView.findViewById(R.id.iv_circle_red);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        NotifyList notifyList = this.notifyList.get(position);
        // TODO: 2017/2/12    主用
//        viewHolder.tv_title.setText(notifyList.getTitle());
//        viewHolder.tv_time.setText(notifyList.getCreateDate());
//        viewHolder.tv_creator.setText(notifyList.getCreator());
//        String content = notifyList.getContent();
//        viewHolder.tv_content.setText(content);
        // TODO: 2017/2/12   测试数据用
        viewHolder.tv_title.setText("人民公安报 - 中国警察网");
        viewHolder.tv_time.setText("2017-2-14");
        viewHolder.tv_content.setText("中国警察网是中国最权威的警务资讯综合门户网站,设有新闻、视频、大要案、经济犯罪预警、出入境信息.....");
        return convertView;
    }

    private static class ViewHolder {
        TextView tv_title;
        TextView tv_content;
        TextView tv_creator;
        TextView tv_time;
        ImageView iv_state;
    }
}
